package com.ybwh.tools;

import java.io.BufferedReader;
import java.io.FileReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

import org.apache.commons.lang3.StringUtils;

public class GenCodeStart {

	public static Connection getConnections(String driver, String url, String user, String pwd) {
		try {
			Class.forName(driver);
			Connection connection = DriverManager.getConnection(url, user, pwd);
			return connection;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	public static void main(String[] args) {
		final String url = "jdbc:mysql://42.62.10.130:3306/ehr_dev?characterEncoding=utf-8&useUnicode=true&zeroDateTimeBehavior=convertToNull";
		final String driver = "com.mysql.jdbc.Driver";
		final String user = "eHRDev";
		final String pwd = "shangde_wings";
//		final String url = "jdbc:mysql://127.0.0.1:3306/sharding_jdbc?characterEncoding=utf-8&useUnicode=true&zeroDateTimeBehavior=convertToNull";
//		final String driver = "com.mysql.jdbc.Driver";
//		final String user = "root";
//		final String pwd = "fan1988";

		try {
			System.out.println(Long.parseLong("41159"));
			System.out.println("start gen code .....");
			Connection conn = getConnections(driver, url, user, pwd);
			String sql = "update t_employee_base_info  set leadercheck_leave_dt=? where employee_id=?";

			BufferedReader reader = new BufferedReader(new FileReader("D:/temp/11.txt"));
			String line = null;
			while (StringUtils.isNotBlank(line = reader.readLine())) {
				System.out.println("["+line.split(",")[0]+"]");
				String employeeId = line.split(",")[0];	
				String leadercheck_leave_dt = line.split(",")[1];
				
				
				PreparedStatement stmt = conn.prepareStatement(sql);
				stmt.setString(1, leadercheck_leave_dt);
				stmt.setString(2, employeeId);
				int n = stmt.executeUpdate();
				System.out.println("****"+n);
			}

			System.out.println("gen code  success!!");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
